<template>
  <div class="login-box">
    <div class="login-logo">
      <a href="/">
        <b>NB</b>center</a>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
      <p class="login-box-msg">登录会话</p>

      <form role="form" v-on:submit.prevent="login">
        <div class="form-group has-feedback">
          <input type="email" autofocus="autofocus" class="form-control" id="login-email" placeholder="Email" required="required" v-model="email">
          <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
          <input type="password" class="form-control" id="login-password" placeholder="Password" required="required" v-model="password">
          <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="row">
          <div class="col-xs-8">
          </div>
          <!-- /.col -->
          <div class="col-xs-4">
            <input type="submit" class="btn btn-primary btn-block btn-flat" id="login-btn" value="登录">
          </div>
          <!-- /.col -->
        </div>
      </form>

      <p>
        <router-link to="/register">
          <i class="fa fa-user-plus"></i>注册新用户</router-link>
      </p>
      <p>
        <a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=852b701ff532423e69e5527abfdb4619a62c3a7bdfa523d3873616a08d1635d4">
          <i class="fa fa-qq"></i>开发者社区</a>
      </p>
    </div>
    <!-- /.login-box-body -->
  </div>
  <!-- /.login-box -->
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      email: "",
      password: "",
    };
  },
  created() {
    if (this.$store.getters.isLogin) {
    }
  },
  methods: {
    login_succ() {
      let redirect = "/general";
      this.$router.push({ path: redirect });
    },
    login() {
      if (!!!this.email || !!!this.password) {
        return;
      }
      let req = this.$store.dispatch('login', {
        email: this.email,
        password: this.password
      });
      req.then(res => {
        this.login_succ();
        this.open_notification(res.email, res.access_token);
      });
    }
  }
}
</script>
